cd "C:\Users\hanollee\Dropbox\BIHS\"

use "Replication.Package\Data\tmp_2018a_male.dta", clear
merge 1:m year a01 using "Replication.Package\Data\tmp_2018b1_male.dta"
rename _merge merge
label var merge "Replication.Package\Data\merge results A+B"
merge m:m year a01 using "Replication.Package\Data\tmp_2018_hsize"
drop _merge
merge 1:1 a01 mid using "Replication.Package\Data\tmp_2018w3_female"
drop _merge
merge 1:1 a01 mid using "Replication.Package\Data\tmp_2018w4_female"
drop _merge
merge 1:1 a01 mid using "Replication.Package\Data\tmp_2018z_female"
drop _merge
merge m:1 a01 using "Replication.Package\Data\158_BIHS sampling weights_r3"
drop _merge
merge m:1 a01 using "Replication.Package\Data\tmp_2015a_region"
drop _merge
merg m:1 a01 mid using "Replication.Package\Data\tmp_2018we7_male"
drop _merge
merg m:1 a01 mid using "Replication.Package\Data\tmp_2018we7_female"
drop _merge

g motheredu =mothereduM
replace motheredu = mothereduF if motheredu==.

g fatheredu =fathereduM
replace fatheredu = fathereduF if fatheredu==.

g whereyouborn =whereyoubornM
replace whereyouborn = whereyoubornF if whereyouborn==.




g myear = 2018-age+mage

g birthyear = 2018-age

keep if birthyear>=1960
g female = (sex == 2)

*keep if sex==2

keep a01 mage popweight myear age birthyear div village female motheredu fatheredu whereyouborn div
keep if age>=9
g id=_n

save "Replication.Package\Data\tmp_Survival_CM.dta", replace

keep a01 id 

expand 38

g mage = 1
bysort id: replace mage = sum(mage)
replace mage = mage+8

merge m:1 a01 id mage using "Replication.Package\Data\tmp_Survival_CM.dta"
drop _merge


sort id mage
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.

replace age = age[_n-1]+1 if id == id[_n-1] & age==. & age[_n-1]!=.

g married_survival = (myear!=.)
replace married_survival = . if id == id[_n-1] & married_survival==0 & married_survival[_n-1]==1
replace married_survival = . if id == id[_n-1] & married_survival==0 & married_survival[_n-1]==.

replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.

replace birthyear = birthyear[_n-1] if id == id[_n-1] & birthyear==. & birthyear[_n-1]!=.


replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.

replace div = div[_n-1] if id == id[_n-1] & div==. & div[_n-1]!=.

replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.

replace motheredu = motheredu[_n-1] if id == id[_n-1] & motheredu==. & motheredu[_n-1]!=.


replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.

replace fatheredu = fatheredu[_n-1] if id == id[_n-1] & fatheredu==. & fatheredu[_n-1]!=.


replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.

replace whereyouborn = whereyouborn[_n-1] if id == id[_n-1] & whereyouborn==. & whereyouborn[_n-1]!=.

replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.

replace female = female[_n-1] if id == id[_n-1] & female==. & female[_n-1]!=.


replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.

replace popweight = popweight[_n-1] if id == id[_n-1] & popweight==. & popweight[_n-1]!=.

replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.

replace div = div[_n-1] if id == id[_n-1] & div==. & div[_n-1]!=.

replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.

replace village = village[_n-1] if id == id[_n-1] & village==. & village[_n-1]!=.

g year = myear

replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.

replace year = year[_n-1]+1 if id == id[_n-1] & year==. & year[_n-1]!=.


merge m:m a01 using  "Replication.Package\Data\precip_z_clean.dta"
drop _merge

merge m:m a01 using  "Replication.Package\Data\temp_clean.dta"
drop _merge


g precip_z = .
forval x = 1951(1)2015{
	replace precip_z = precip_z`x' if year==`x'
}

g extremeheat = .
forval x = 1961(1)2015{
	replace extremeheat = extremeheat`x' if year==`x'
}



g precip_zL1 = .
forval x = 1951(1)2014{
	replace precip_zL1 = precip_z`x' if year==`x'+1
}

g extremeheatL1 = .
forval x = 1961(1)2014{
	replace extremeheatL1 = extremeheat`x' if year==`x'+1
}


g precip_zL2 = .
forval x = 1951(1)2013{
	replace precip_zL2 = precip_z`x' if year==`x'+2
}

g extremeheatL2 = .
forval x = 1961(1)2013{
	replace extremeheatL2 = extremeheat`x' if year==`x'+2
}


drop precip_z1951 -  extremeheat2015

keep if mage<18


egen gridcell = group(latitude longitude)

save "Replication.Package\Data\survival_CM.dta", replace
